export const arrayToTree=(items)=>{
    const result = [];   // 存放结果集
    const itemMap = {};  // 将数组转化为map，暂时存放在这里
    for (const item of items) {
        const id = item.key;
        const pid = item.parent;

        if (!itemMap[id]) {
            itemMap[id] = {
                children: [],
            }
        }

        itemMap[id] = {
            ...item,
            children: itemMap[id]['children']
        }

        const treeItem =  itemMap[id];

        if (!pid) {
            result.push(treeItem);
        } else {
            if (!itemMap[pid]) {
                itemMap[pid] = {
                    children: [],
                }
            }
            itemMap[pid].children.push(treeItem)
        }

    }
    return result;
}
